/*
 * @Author: modefy
 * @Date: 2021-12-06 10:13:57
 * @LastEditors: modefy
 * @LastEditTime: 2023-05-15 15:46:14
 * @Description: Description
 */
import { ref } from 'vue'
import { getKnowldList, deleteKnow } from 'api/knowledge'
import { toast } from 'utils/toast'

// 知识列表 业务代码（前后端对接层）
// 不能将类型“null”分配给类型“Record<string, any> | undefined
export let tableData = ref([])
export let total = ref<Number>(0)

export const getKnowList = () => {
  getKnowldList().then((data) => {
    if (data.code === 200) {
      tableData.value = data.data.data
      total.value = data.data.total
    } else {
      toast(data.msg)
    }
  })
}

export const handleDelete = (id: number) => {
  deleteKnow(id).then(async (data) => {
    if (data.code === 200) {
      toast(data.msg)
      await getKnowList()
    } else {
      toast(data.msg)
    }
  })
}
